<template>
  <!-- 所有商户列表 -->
  <div class="material-auth">
    <div class="list" v-if="list.length">
      <div class="item" v-for="(item, index) in list" :key="index">
        <img :src="item.head_image" alt="" class="avatar" v-if="item.head_image"/>
        <img src="@/assets/image/default-avatar.jpeg" alt="" class="avatar" v-else/>
        <div class="item-center">
          <span class="name">{{ item.username }}</span>
          <span class="auth" :class="{'gray': item.authorize_type_enum !== 'ALL_AUTHORIZE'}">{{ authDict[item.authorize_type_enum] }}</span>
        </div>
        <span class="change-btn" @click="changeAuth(item)">修改授权</span>
      </div>
    </div>
    <div class="no-data" v-if="!list.length">
      <span>暂无商户</span>
    </div>
  </div>
</template>

<script>
import { listMerchant } from '@/api/account'
import { getOssDomain } from '@/api/oss'
export default {
  data () {
    return {
      list: [],
      authDict: {
        'ALL_AUTHORIZE': '全部授权',
        'PART_AUTHORIZE': '部分授权',
        'NOT_AUTHORIZE': '不授权'
      },
      oss_domain: '',
    }
  },
  async mounted () {
    if (!sessionStorage.getItem('oss_domain')) {
      const res = await getOssDomain()
      sessionStorage.setItem('oss_domain', res.domain)
      this.oss_domain = res.domain
    } else {
      this.oss_domain = sessionStorage.getItem('oss_domain')
    }
    this.getAccountList()
    document.title = '素材包授权'
  },
  methods: {
    getAccountList () {
      listMerchant({ group_id: null}).then(res => {
        console.log('查看素有商户：', res)
        res.forEach(item => {
          if (item.head_image) item.head_image = `${this.oss_domain}/${item.head_image}`
        })
        this.list = res.filter(i => i.status === "AUDIT_PASS")
      })
    },
    changeAuth (item) {
      this.$router.push({
        path: '/changeMaterialAuth',
        query: {
          type_key: item.authorize_type_enum,
          account_id: item.id
        }
      })
    }
  }
}
</script>

<style scoped>
.no-data {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
}
.material-auth {
  min-height: 100vh;
  display: flex;
  box-sizing: border-box;
  flex-direction: column;
  justify-content: center;
}
.list {
  padding-top: 4.5vw;
  flex: 1;
}
.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 89.6vw;
  height: 19.2vw;
  box-sizing: border-box;
  margin: 0 auto 3.2vw;
  background: #ffffff;
  border-radius: 2.13vw;
  padding: 0 2.67vw 0 3.2vw;
}
.item-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* padding-top: 3.2vw; */
}
.avatar {
  width: 12.27vw;
  height: 12.27vw;
  border-radius: 50%;
  margin-right: 2.13vw;
}
.name {
  margin-bottom: .4vw;
  font-family: Source Sans Pro;
  font-size: 3.73vw;
  font-weight: bold;
  line-height: 5.87vw;
  color: #3D3D3D;
}
.auth {
  font-family: Source Sans Pro;
  font-size: 3.2vw;
  font-weight: 600;
  line-height: 5.87vw;
  color: #00A6A7;
}
.change-btn {
  font-family: Source Sans Pro;
  font-size: 3.73vw;
  font-weight: 600;
  color: #0A67FF;
}
.gray {
  color: #999999!important;
}
</style>